#!/bin/sh
set -x

module=$1
version=$2


dist=zeus_web_$(date +%Y%m%d)_${version}


pack(){
  ssh root@sh1-int-static-arch-dom-web-prod-1 \
  'cd /data/deploy_code/zeus-web;git pull;npm run build:prod;cd dist;tar -zcf '"${dist}"'.tar.gz *;mv '"${dist}"'.tar.gz /data/deploy_package/'
}

push(){
  ssh root@sh1-int-static-arch-dom-web-prod-1 \
  'scp -o StrictHostKeyChecking=no /data/deploy_package/'"${dist}.tar.gz"' root@sh1-int-static-arch-zeus-web-prod-1:/data/deploy_package/;' \
  'scp -o StrictHostKeyChecking=no /data/deploy_package/'"${dist}.tar.gz"' root@sh1-int-static-arch-zeus-web-prod-2:/data/deploy_package/;' \
  'scp -o StrictHostKeyChecking=no /data/deploy_package/'"${dist}.tar.gz"' root@tx1-int-static-arch-zeus-web-prod-1:/data/deploy_package/;' \
  'scp -o StrictHostKeyChecking=no /data/deploy_package/'"${dist}.tar.gz"' root@tx1-int-static-arch-zeus-web-prod-2:/data/deploy_package/;'
}

unzip(){
	ssh root@sh1-int-static-arch-zeus-web-prod-1 'cd /usr/local/nginx/ROOT_WEB; rm -rf static;tar -xvf /data/deploy_package/'${dist}.tar.gz
	ssh root@sh1-int-static-arch-zeus-web-prod-2 'cd /usr/local/nginx/ROOT_WEB; rm -rf static;tar -xvf /data/deploy_package/'${dist}.tar.gz
	ssh root@tx1-int-static-arch-zeus-web-prod-1 'cd /usr/local/nginx/ROOT_WEB; rm -rf static;tar -xvf /data/deploy_package/'${dist}.tar.gz
	ssh root@tx1-int-static-arch-zeus-web-prod-2 'cd /usr/local/nginx/ROOT_WEB; rm -rf static;tar -xvf /data/deploy_package/'${dist}.tar.gz
}

if [ "${module}" = "pack" ];then
    pack $;
elif [ "${module}" = "push" ];then
    push $;
elif [ "${module}" = "unzip" ];then
    unzip $;
elif [ "${module}" = "deploy" ];then
    pack $;
    push $;
    unzip $;
else echo "please input the right module."
fi


